//package com.crm.jdy.controller.backups;
//
//
//import com.crm.jdy.common.dto.ActivitiBasunessDto;
//import com.crm.jdy.common.pojo.ActivitiBasuness;
//import com.crm.jdy.common.utils.api.ResultVo;
//import com.crm.jdy.common.utils.currentlimiting.RateLimit;
//import com.github.pagehelper.PageInfo;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.servlet.ModelAndView;
//
//import java.io.*;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.Map;
//
//@Validated
//@Api(tags = "backupsMysql", description = "数据库的备份操作")
//@RestController
//@RequestMapping("/backupsMysql")
//public class BackupsMysql {
//
//
//
//    @RateLimit()
//    @ApiOperation("MySql数据库备份")
//    @GetMapping("/mysqlBackups")
//    public ModelAndView mysqlBackups(){
//     Map  map =new HashMap();
//
//        String fileName = "backup_" + new Date().getTime() + ".sql";
//        String cmd =  "mysqldump -uroot -p123456 dbName > " + projectUrlConfig.getBackPath() + fileName; //-u后的root为mysql数据库用户名，-p后接的123456为该用户密码，注意不要有空格；dbName填写需要备份数据的数据库名称，大于号后接生成文件路径
//        try {
//            Runtime.getRuntime().exec(cmd);
//        }catch (Exception e){
////            log.error("【备份数据库】失败：{}", e.getMessage());
//            map.put("msg", e.getMessage());
//            return new ModelAndView("common/error", map);
//        }
////        log.info("【备份数据库】成功，SQL文件：{}", fileName);
//        map.put("msg","备份数据库成功");return new ModelAndView("common/success", map);
//
//        return  ResultVo.success();
//    }
//
//
//    @GetMapping("rollback")
//    public ModelAndView rollback(@RequestParam("filename") String fileName, Map<String, Object> map){
//        String path = projectUrlConfig.getBackPath() + fileName;
//
//        try {
//            Runtime runtime = Runtime.getRuntime();
//            Process process = runtime.exec("mysql -uroot -p123456 --default-character-set=utf8 dbName");
//            OutputStream outputStream = process.getOutputStream();
//            FileInputStream fis = new FileInputStream(path);
//            InputStreamReader isr = new InputStreamReader(fis, "utf-8");
//            BufferedReader br = new BufferedReader(isr);
//            String str = null;
//            StringBuffer sb = new StringBuffer();
//            while ((str = br.readLine()) != null) {
//                sb.append(str + "\r\n");
//            }
//            str = sb.toString();
//            OutputStreamWriter writer = new OutputStreamWriter(outputStream,"utf-8");
//            writer.write(str);
//            writer.flush();
//            if(writer!=null){
//                writer.close();
//            }
//            if(br!=null){
//                br.close();
//            }
//            if(isr!=null){
//                isr.close();
//            }
//            if(fis!=null){
//                fis.close();
//            }
//            if(outputStream!=null){
//                outputStream.close();
//            }
//        }catch (Exception e){
////            log.error("【还原数据库】失败：{}", e.getMessage());
//            map.put("msg", e.getMessage());
//            return new ModelAndView("common/error", map);
//        }
////        log.info("【还原数据库】成功，还原文件：{}", fileName);
//        map.put("msg","还原数据库成功");return new ModelAndView("common/success", map);
//    }
//
//
//
//}
